package leetcode;

/**
 * 反转链表
 * 算法：链表
 * 就是把指针反向一下
 */
public class _206 {

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode reverseList(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode cur = head;
        ListNode newNode = new ListNode(cur.val, null);
        while (cur.next != null) {
            cur = cur.next;
            newNode.next = new ListNode(newNode.val, newNode.next);
            newNode.val = cur.val;
        }
        return newNode;
    }

}
